/**
 * ------------------------------------------------------------------------------------------
 * Copyright (c): Company, 2012 This software is the
 * proprietary information of FHWS, Würzburg All Right Reserved.
 * ------------------------------------------------------------------------------------------
 *
 *
 * @project: Vorlesungplan
 * @copyright FHWS 2012
 * @link       http://mussnocheingeragenwerden.de
 * @package    tt.model
 *
 * SVN revision information:
 *
 * @version $Rev$:
 * @author $Author$:
 * @date $Date$:
 */
package tt.model;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@Table(name = "courseofstudy")
@XmlRootElement
@NamedQueries(
{
   @NamedQuery(name = "Courseofstudy.findAll", query = "SELECT c FROM Courseofstudy c  order by c.coursename"),
   @NamedQuery(name = "Courseofstudy.findByIdcourse", query = "SELECT c FROM Courseofstudy c WHERE c.idcourse = :idcourse"),
   @NamedQuery(name = "Courseofstudy.findByCoursename", query = "SELECT c FROM Courseofstudy c WHERE c.coursename = :coursename"),
   @NamedQuery(name = "Courseofstudy.findByCourseshortcut", query = "SELECT c FROM Courseofstudy c WHERE c.courseshortcut = :courseshortcut")
})
public class Courseofstudy implements Serializable, Comparable<Courseofstudy>
{

   private static final long serialVersionUID = 1L;
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   @Basic(optional = false)
   @Column(name = "idcourse")
   private Integer idcourse;
   @Basic(optional = false)
   @NotNull
   @Size(min = 1, max = 45)
   @Column(name = "coursename")
   private String coursename;
   @Basic(optional = false)
   @NotNull
   @Size(min = 1, max = 10)
   @Column(name = "courseshortcut")
   private String courseshortcut;
   @OneToMany(cascade = CascadeType.ALL, mappedBy = "courseofstudy")
   private Collection<Semester> semesterCollection;

   public Courseofstudy()
   {
   }

   public Courseofstudy(Integer idcourse)
   {
      this.idcourse = idcourse;
   }

   public Courseofstudy(Integer idcourse, String coursename, String courseshortcut)
   {
      this.idcourse = idcourse;
      this.coursename = coursename;
      this.courseshortcut = courseshortcut;
   }

   public Integer getIdcourse()
   {
      return idcourse;
   }

   public void setIdcourse(Integer idcourse)
   {
      this.idcourse = idcourse;
   }

   public String getCoursename()
   {
      return coursename;
   }

   public void setCoursename(String coursename)
   {
      this.coursename = coursename;
   }

   public String getCourseshortcut()
   {
      return courseshortcut;
   }

   public void setCourseshortcut(String courseshortcut)
   {
      this.courseshortcut = courseshortcut;
   }

   @XmlTransient
   public Collection<Semester> getSemesterCollection()
   {
      Collections.sort((List<Semester>) semesterCollection);
      return semesterCollection;
   }

   public void setSemesterCollection(Collection<Semester> semesterCollection)
   {
      this.semesterCollection = semesterCollection;
   }

   @Override
   public int hashCode()
   {
      int hash = 0;
      hash += (idcourse != null ? idcourse.hashCode() : 0);
      return hash;
   }

   @Override
   public boolean equals(Object object)
   {
      // TODO: Warning - this method won't work in the case the id fields are not set
      if (!(object instanceof Courseofstudy))
      {
         return false;
      }
      Courseofstudy other = (Courseofstudy) object;
      if ((this.idcourse == null && other.idcourse != null) || (this.idcourse != null && !this.idcourse.equals(other.idcourse)))
      {
         return false;
      }
      return true;
   }

   @Override
   public String toString()
   {
      return "tt.model.Courseofstudy[ idcourse=" + idcourse + " ]";
   }

   public int compareTo(Courseofstudy o)
   {
      return coursename.compareToIgnoreCase(o.getCoursename());

   }//endmethod
}
